#!/bin/bash

ICTCLAS=~/workspace/source/ictclas/ictclas
MMSEG=/usr/local/bin/mmseg
MMSEG_DICT_PATH=~/workspace/source/mmseg-0.7.3/data
SCWS=~/workspace/source/scws-1.0.4/cli/scws
SCWS_DICT=~/workspace/source/scws-1.0.4/etc/dict.utf8.xdb
SCWS_RULE=~/workspace/source/scws-1.0.4/etc/rules.utf8.ini
HISEG=~/workspace/hiseg/clas/segment
HISEG_DICT=~/workspace/hiseg/clasdict/
SCORE=~/workspace/source/icwb/scripts/score

DP=msr
DP=pku

SRC_GBK=~/workspace/source/icwb/testing/"$DP"_test.txt
SRC_UTF8=~/workspace/source/icwb/testing/"$DP"_test.utf8
GOLD_GBK=~/workspace/source/icwb/gold/"$DP"_test_gold.txt
GOLD_UTF8=~/workspace/source/icwb/gold/"$DP"_test_gold.utf8
WORDS_GBK=~/workspace/source/icwb/gold/"$DP"_training_words.txt
WORDS_UTF8=~/workspace/source/icwb/gold/"$DP"_training_words.utf8

DST_ICTCLAS=~/workspace/hiseg/testcase/dst_ictclas
DST_ICTCLAS_GBK=~/workspace/hiseg/testcase/dst_ictclas_gbk
DST_MMSEG=~/workspace/hiseg/testcase/dst_mmseg
DST_SCWS=~/workspace/hiseg/testcase/dst_scws
DST_HISEG=~/workspace/hiseg/testcase/dst_hiseg
RES_ICTCLAS=~/workspace/hiseg/testcase/res_ictclas
RES_MMSEG=~/workspace/hiseg/testcase/res_mmseg
RES_SCWS=~/workspace/hiseg/testcase/res_scws
RES_HISEG=~/workspace/hiseg/testcase/res_hiseg

ictclas()
{
	echo 'ictclas'
	time $ICTCLAS < $SRC_GBK >$DST_ICTCLAS_GBK
	iconv -f gbk -t utf8 -c $DST_ICTCLAS_GBK >$DST_ICTCLAS
	[ "$1" != '--noscore' ] && wc -l $SRC_UTF8 && $SCORE $WORDS_UTF8 $GOLD_UTF8 $DST_ICTCLAS>$RES_ICTCLAS
}
mmseg()
{
	echo 'mmseg'
	time $MMSEG -d $MMSEG_DICT_PATH $SRC_UTF8 >$DST_MMSEG
	[ "$1" != '--noscore' ] && wc -l $SRC_UTF8 && $SCORE $WORDS_UTF8 $GOLD_UTF8 $DST_MMSEG>$RES_MMSEG 
}
scws()
{
	echo 'scws'
	time $SCWS -c utf8 -d $SCWS_DICT -i $SRC_UTF8 >$DST_SCWS
	[ "$1" != '--noscore' ] && wc -l $SRC_UTF8 && $SCORE $WORDS_UTF8 $GOLD_UTF8 $DST_SCWS>$RES_SCWS
}
hiseg()
{
	echo 'hiseg'
	time $HISEG -f $SRC_UTF8 -d $HISEG_DICT/hidict.dat -c $HISEG_DICT/unknown.ctx -r $HISEG_DICT/nr.ctx -s $HISEG_DICT/ns.ctx -t $HISEG_DICT/tr.ctx >$DST_HISEG
	[ "$1" != '--noscore' ] && wc -l $SRC_UTF8 && $SCORE $WORDS_UTF8 $GOLD_UTF8 $DST_HISEG>$RES_HISEG
}


if [ $# == 0 ];then
	hiseg
elif [ "$1" == '--ictclas' ];then
	ictclas
elif [ "$1" == '--mmseg' ];then
	mmseg
elif [ "$1" == '--scws' ];then
	scws
elif [ "$1" == '--hiseg' ];then
	hiseg
elif [ "$1" == '--all' ];then
	ictclas
	mmseg
	scws
	hiseg
elif [ "$1" == '--view' ];then
	vi $RES_HISEG
elif [ "$1" == '--clean' ];then
	rm $DST_ICTCLAS $DST_ICTCLAS_GBK $DST_MMSEG $RES_ICTCLAS $RES_MMSEG $DST_SCWS $RES_SCWS 
fi
